Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.3, n = 288)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.51065 11.55180 11.59248 11.63269 11.67246 11.71180 11.75072 11.78924
## [9] 11.82738 11.86516 11.90259 11.93968 11.97646 12.01291 12.04898 12.08466
## [17] 12.11992 12.15473 12.18908 12.22294 12.25651 12.28994 12.32314 12.35602
## [25] 12.38848 12.42043 12.45179 12.48246 12.51234 12.54216 12.57245 12.60280
## [33] 12.63283 12.66215 12.69037 12.71709 12.74358 12.77113 12.79935 12.82786
## [41] 12.85629 12.88426 12.91140 12.93732 12.96166 12.98402 13.00404 13.02133
## [49] 13.03862 13.05796 13.07801 13.09742 13.11483 13.12890 13.13828 13.14472
## [57] 13.15065 13.15575 13.15971 13.16221 13.16291 13.16151 13.15768 13.15111
## [65] 13.14014 13.12426 13.10485 13.08331 13.06100 13.03932 13.01965 12.99792
## [73] 12.96993 12.93681 12.89973 12.85981 12.81821 12.77608 12.73456 12.69480
## [81] 12.65795 12.62515 12.59755 12.57059 12.54003 12.50751 12.47466 12.44314
## [89] 12.41457 12.39060 12.36954 12.34870 12.32826 12.30836 12.28918 12.27088
## [97] 12.25360 12.23753 12.22280 12.21013 12.19973 12.19104 12.18351 12.17657
## [105] 12.16968 12.16227 12.15537 12.15024 12.14667 12.14446 12.14340 12.14329
## [113] 12.14392 12.14509 12.14659 12.14822 12.14977 12.15105 12.15328 12.15743
## [121] 12.16288 12.16900 12.17519 12.18080 12.18524 12.19010 12.19702 12.20543
## [129] 12.21471 12.22430 12.23360 12.24201 12.24896 12.25385 12.25795 12.26272
## [137] 12.26782 12.27293 12.27774 12.28191 12.28513 12.28632 12.28497 12.28159
## [145] 12.27669 12.27077 12.26436 12.25795 12.25207 12.24722 12.24390 12.24265
## [153] 12.24395 12.24833 12.25629 12.26490 12.27162 12.27753 12.28376 12.29139
## [161] 12.30153 12.31527 12.33365 12.35643 12.38280 12.41198 12.44317 12.47559
## [169] 12.50843 12.54090 12.57221 12.60157 12.62818 12.65126 12.67639 12.70878
## [177] 12.74707 12.78985 12.83575 12.88339 12.93139 12.97836 13.02292 13.06369
## [185] 13.09928 13.12833 13.14943 13.16121 13.16794 13.17444 13.18014 13.18449
## [193] 13.18693 13.18692 13.18388 13.17727 13.16653 13.14741 13.11813 13.08185
## [201] 13.04172 13.00089 12.96252 12.92974 12.89690 12.85704 12.81139 12.76120
## [209] 12.70769 12.65211 12.59569 12.53966 12.48527 12.43374 12.38632 12.34424
## [217] 12.30351 12.26012 12.21526 12.17012 12.12588 12.08375 12.04490 12.00694
## [225] 11.96715 11.92628 11.88509 11.84433 11.80474 11.76708 11.73209 11.70052
## [233] 11.67016 11.63887 11.60749 11.57686 11.54784 11.52127 11.49799 11.47655
## [241] 11.45511 11.43400 11.41352 11.39399 11.37572 11.35903 11.34424 11.33165
## [249] 11.32159 11.31436 11.31028 11.30830 11.30739 11.30786 11.31005 11.31426
## [257] 11.32083 11.33007 11.34147 11.35440 11.36897 11.38531 11.40355 11.42381
## [265] 11.44621 11.47087 11.49793 11.52712 11.55814 11.59105 11.62593 11.66283
## [273] 11.70182 11.74296 11.78622 11.83152 11.87885 11.92820 11.97959 12.03300
## [281] 12.08842 12.14586 12.20531 12.26677 12.33023 12.39569 12.46315 12.53260
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.3, n = 288)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.73198 10.82239 10.91103 10.99789 11.08295 11.16619 11.24759 11.32712
## [9] 11.40479 11.48056 11.55441 11.62634 11.69632 11.76435 11.83049 11.89476
## [17] 11.95721 12.01785 12.07672 12.13386 12.18906 12.24214 12.29321 12.34235
## [25] 12.38967 12.43526 12.47922 12.52164 12.56262 12.60161 12.63818 12.67261
## [33] 12.70518 12.73616 12.76584 12.79449 12.82126 12.84527 12.86675 12.88596
## [41] 12.90314 12.91853 12.93239 12.94495 12.95646 12.96716 12.97731 12.98714
## [49] 12.99337 12.99384 12.99041 12.98500 12.97949 12.97577 12.97573 12.97711
## [57] 12.97664 12.97472 12.97173 12.96806 12.96411 12.96028 12.95694 12.95449
## [65] 12.95332 12.95313 12.95329 12.95316 12.95212 12.94954 12.94478 12.93830
## [73] 12.93099 12.92289 12.91402 12.90442 12.89411 12.88314 12.87152 12.85929
## [81] 12.84649 12.83314 12.81927 12.80444 12.78840 12.77150 12.75406 12.73643
## [89] 12.71893 12.70192 12.68594 12.67100 12.65659 12.64220 12.62732 12.61145
## [97] 12.59407 12.57469 12.55279 12.52695 12.49705 12.46447 12.43060 12.39684
## [105] 12.36456 12.33517 12.30375 12.26551 12.22204 12.17495 12.12582 12.07626
## [113] 12.02785 11.98220 11.94089 11.90553 11.87770 11.85901 11.84519 11.83140
## [121] 11.81837 11.80681 11.79743 11.79098 11.78815 11.78981 11.79578 11.80520
## [129] 11.81721 11.83096 11.84560 11.86027 11.87412 11.88630 11.90110 11.92204
## [137] 11.94704 11.97405 12.00101 12.02585 12.04651 12.06696 12.09207 12.12117
## [145] 12.15357 12.18858 12.22551 12.26369 12.30242 12.34102 12.37881 12.41510
## [153] 12.44921 12.48044 12.50812 12.53338 12.55792 12.58191 12.60552 12.62891
## [161] 12.65225 12.67572 12.69859 12.72019 12.74066 12.76017 12.77889 12.79696
## [169] 12.81456 12.83184 12.84897 12.86611 12.88342 12.90107 12.92143 12.94621
## [177] 12.97456 13.00564 13.03858 13.07253 13.10665 13.14008 13.17196 13.20145
## [185] 13.22769 13.24984 13.26703 13.27842 13.28671 13.29489 13.30252 13.30914
## [193] 13.31431 13.31759 13.31853 13.31669 13.31161 13.30294 13.29099 13.27634
## [201] 13.25958 13.24129 13.22207 13.20248 13.18104 13.15610 13.12810 13.09745
## [209] 13.06456 13.02984 12.99371 12.95660 12.91890 12.88104 12.84343 12.80649
## [217] 12.76489 12.71512 12.66032 12.60363 12.54820 12.49717 12.45367 12.41177
## [225] 12.36448 12.31337 12.26001 12.20596 12.15278 12.10206 12.05534 12.01421
## [233] 11.97529 11.93477 11.89359 11.85271 11.81305 11.77555 11.74115 11.70866
## [241] 11.67643 11.64468 11.61366 11.58360 11.55476 11.52735 11.50163 11.47783
## [249] 11.45619 11.43695 11.42035 11.40489 11.38940 11.37462 11.36125 11.35002
## [257] 11.34166 11.33689 11.33465 11.33355 11.33382 11.33568 11.33935 11.34506
## [265] 11.35304 11.36350 11.37669 11.39209 11.40916 11.42803 11.44883 11.47169
## [273] 11.49675 11.52413 11.55377 11.58553 11.61939 11.65534 11.69339 11.73352
## [281] 11.77574 11.82003 11.86639 11.91481 11.96529 12.01783 12.07241 12.12903
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.3, n = 288)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.84453 10.90659 10.96758 11.02749 11.08627 11.14390 11.20037 11.25563
## [9] 11.30967 11.36246 11.41396 11.46417 11.51304 11.56065 11.60710 11.65241
## [17] 11.69658 11.73963 11.78157 11.82240 11.86191 11.89996 11.93664 11.97207
## [25] 12.00634 12.03957 12.07186 12.10332 12.13406 12.16283 12.18882 12.21273
## [33] 12.23527 12.25714 12.27906 12.30175 12.32483 12.34744 12.36953 12.39103
## [41] 12.41190 12.43208 12.45150 12.47012 12.48788 12.50472 12.52058 12.53542
## [49] 12.55113 12.56887 12.58746 12.60571 12.62243 12.63646 12.64660 12.65348
## [57] 12.65863 12.66224 12.66447 12.66549 12.66549 12.66462 12.66308 12.66102
## [65] 12.65740 12.65143 12.64372 12.63485 12.62541 12.61601 12.60723 12.59763
## [73] 12.58559 12.57144 12.55551 12.53815 12.51967 12.50041 12.48071 12.46090
## [81] 12.44131 12.42227 12.40412 12.38296 12.35618 12.32606 12.29488 12.26492
## [89] 12.23846 12.21778 12.19978 12.18025 12.15980 12.13902 12.11852 12.09890
## [97] 12.08076 12.06471 12.05134 12.04108 12.03339 12.02745 12.02242 12.01749
## [105] 12.01181 12.00457 11.99686 11.99026 11.98457 11.97964 11.97529 11.97135
## [113] 11.96765 11.96402 11.96029 11.95628 11.95183 11.94677 11.94191 11.93802
## [121] 11.93488 11.93227 11.92997 11.92775 11.92539 11.92434 11.92571 11.92878
## [129] 11.93282 11.93711 11.94092 11.94351 11.94418 11.94218 11.93598 11.92563
## [137] 11.91279 11.89913 11.88631 11.87600 11.86985 11.86465 11.85649 11.84603
## [145] 11.83393 11.82086 11.80746 11.79440 11.78234 11.77193 11.76384 11.75872
## [153] 11.75723 11.76003 11.76779 11.77935 11.79292 11.80818 11.82482 11.84252
## [161] 11.86096 11.87982 11.90106 11.92639 11.95510 11.98653 12.01999 12.05478
## [169] 12.09021 12.12562 12.16030 12.19357 12.22474 12.25313 12.28407 12.32245
## [177] 12.36694 12.41619 12.46889 12.52368 12.57924 12.63424 12.68733 12.73718
## [185] 12.78246 12.82184 12.85396 12.87751 12.89723 12.91813 12.93928 12.95974
## [193] 12.97859 12.99488 13.00769 13.01608 13.01911 13.01597 13.00733 12.99452
## [201] 12.97886 12.96168 12.94430 12.92806 12.90967 12.88555 12.85656 12.82355
## [209] 12.78740 12.74895 12.70908 12.66863 12.62847 12.58947 12.55247 12.51834
## [217] 12.48037 12.43359 12.38149 12.32756 12.27528 12.22816 12.18967 12.15267
## [225] 12.10907 12.06093 12.01034 11.95934 11.91002 11.86445 11.82469 11.79282
## [233] 11.76411 11.73343 11.70225 11.67205 11.64429 11.62046 11.60202 11.59037
## [241] 11.58518 11.58540 11.58995 11.59774 11.60772 11.61881 11.62993 11.64000
## [249] 11.64797 11.65274 11.65326 11.65241 11.65334 11.65537 11.65784 11.66005
## [257] 11.66134 11.66101 11.65994 11.65939 11.65926 11.65945 11.65987 11.66043
## [265] 11.66103 11.66157 11.66195 11.66269 11.66416 11.66612 11.66828 11.67040
## [273] 11.67222 11.67346 11.67430 11.67506 11.67577 11.67641 11.67701 11.67757
## [281] 11.67809 11.67859 11.67908 11.67955 11.68003 11.68051 11.68101 11.68152
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")